<?php

namespace Main\Model;

// 控制器基类
use FC\Model\BaseModel;

class menus extends BaseModel
{

    function __construct()
    {
		// 数据库配置类型,默认为Mysql
		//$this->db_type = 'Mysql';		
		// 数据库配置链接名称,默认为default
		//$this->db_config_name = 'default';

        // 执行父类
        parent::__construct();
    }

    //处理一下菜单的数组
    public function menu_array($re, $spread = '')
    {
        $arr = [];
        if (is_array($re) && count($re) >= 1) {
            foreach ($re as $key => $value) {
                if (empty($value['spread_id']) && empty($spread)) {
                    $arr[$key] = $value;
                    $arr[$key]['spread'] = 'true';
                    $arr[$key]['childs'] = $this->menu_array($re, $value['id']);
                } else {
                    if ($value['spread_id'] == $spread) {
                        unset($value['id']);
                        unset($value['spread_id']);
                        $arr[] = $value;
                    }
                }
            }
        }
        $re = array_values($arr);
        return $re;
    }

    // 获取菜单
    public function getmenu()
    {
        $data['limit'] = 50;
        $data['status'] = 1;
        $res = $this->query($data);
        if ($res) {
            $res = $this->menu_array($res['data']);
        }
        return $res;
    }
}
